function alertDelay(state, message, time) {
    $('#alert').stop();
    if (time == null) {
        time = 1500;
    }
    switch (state) {
        case 1:
            var success = createRandomId();
            $('<div>').appendTo('#alert').attr('id', success).css("width", "100%").addClass('alert alert-success').html(message).show().delay(time).fadeOut(function() {
                $("#" + success).remove();
            });
            break;
        case 2:
            var info = createRandomId();
            $('<div>').appendTo('#alert').attr('id', info).css("width", "100%").addClass('alert alert-info').html(message).show().delay(time).fadeOut(function() {
                $("#" + info).remove();
            });
            break;
        case 3:
            var warning = createRandomId();
            $('<div>').appendTo('#alert').attr('id', warning).css("width", "100%").addClass('alert alert-warning').html(message).show().delay(time).fadeOut(function() {
                $("#" + warning).remove();
            });
            break;
        case 4:
            var danger = createRandomId();
            $('<div>').appendTo('#alert').attr('id', danger).css("width", "100%").addClass('alert alert-danger').html(message).show().delay(time).fadeOut(function() {
                $("#" + danger).remove();
            });
            break;
    }

    function createRandomId() {      
        return (Math.random() * 100).toString(16).substr(0, 4) + '-' + (new Date()).getTime() + '-' + Math.random().toString().substr(2, 5);  
    }
}